//
//  DefaultViewController.m
//  nonghubao
//
//  Created by 王 文彬 on 13-1-25.
//  Copyright (c) 2013年 mypocketbaby. All rights reserved.
//

/*
 SUMMARY
 
 本类处理用户没有登录的情况下，显示的默认界面。界面包含中部的一个ScrollView，和底部的两个按钮。
 
*/


#import "DefaultViewController.h"
#import "Config.h"
#import "MobileFormViewController.h"
#import "LoginFormViewController.h"
#import "Helper.h"

@interface DefaultViewController ()

@end

@implementation DefaultViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    //标题
    self.title = _L(@"vc_title_001");
    
    UIView *pictureView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, _SYS_SCREEN_HEIGHT)];
    
    UIImage *image = nil;
    
    if (iPhone5) {
        
        image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_img_007_b-568h@2x" ofType:@"jpg"]];
    
    }else{
        
        image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"com_img_007_n@2x" ofType:@"jpg"]];

    }
    
    pictureView.backgroundColor = [UIColor colorWithPatternImage:image];
    
    //注册
    UIButton* registerButton = [[UIButton alloc] initWithFrame:CGRectMake(10.0f, _SYS_SCREEN_HEIGHT - 70.0f, 145.0f, 40.0f)];

    if (iPhone5) {
        
        registerButton.frame = CGRectMake(10.0f, _SYS_SCREEN_HEIGHT - 80.0f, 145.0f, 40.0f);
    
    }
    registerButton.titleLabel.font = _SYS_FONT_006;
    [registerButton setBackgroundImage:[UIImage imageNamed:@"com_btn_024_n"] forState:UIControlStateNormal];
    [registerButton setTitle:@"注册" forState:UIControlStateNormal];
    [registerButton setTitleColor:[UIColor colorWithRed:124/255.0f green:167/255.0f blue:2/255.0f alpha:1.0f] forState:UIControlStateNormal];
    [registerButton addTarget:self action:@selector(registerButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    [pictureView addSubview:registerButton];
    
    //登录
    UIButton* loginButton = [[UIButton alloc] initWithFrame:CGRectMake(registerButton.frame.origin.x + registerButton.frame.size.width + 10.0f, _SYS_SCREEN_HEIGHT - 70.0f, 145.0f, 40.0f)];
    if (iPhone5) {
        
        loginButton.frame = CGRectMake(registerButton.frame.origin.x + registerButton.frame.size.width + 10.0f, _SYS_SCREEN_HEIGHT - 80.0f, 145.0f, 40.0f);
    }
    loginButton.titleLabel.font = _SYS_FONT_006;
    [loginButton setBackgroundImage:[UIImage imageNamed:@"com_btn_025_n"] forState:UIControlStateNormal];
    [loginButton setTitle:@"登录" forState:UIControlStateNormal];
    [loginButton setTitleColor:[UIColor colorWithRed:255/255.0f green:255/255.0f blue:253/255.0f alpha:1.0f] forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(loginButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    [pictureView addSubview:loginButton];
    
    [self.view addSubview:pictureView];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"Default_Started" object:nil];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 事件

// 注册按钮点击事件
//
- (void)registerButtonEvent:(id)sender
{
    //设定一个全局的值，用于MobileFormVC和PasswordFormVC判断是注册还是找回密码
    [[NSUserDefaults standardUserDefaults] setBool:true forKey:@"isRegisterOrNot"];

    //创建注册视图
    MobileFormViewController *mobileFormVC = [[MobileFormViewController alloc] init];
    mobileFormVC.title = _L(@"vc_title_005");
    [mobileFormVC agreementAppear];
    //使用一个NavigationController来包裹注册视图
    UINavigationController* mobileFomNC = [[UINavigationController alloc] initWithRootViewController:mobileFormVC];
    [Helper navigationControllerCommonStyle:mobileFomNC];
    
    //使用presentModal方式
    [self.navigationController presentModalViewController:mobileFomNC animated:true];
}


// 登录按钮点击事件
- (void)loginButtonEvent:(id)sender
{
    //设定一个全局的值，用于MobileFormVC判断是注册还是找回密码
    [[NSUserDefaults standardUserDefaults] setBool:false forKey:@"isRegisterOrNot"];
    
    //创建登录视图
    LoginFormViewController* loginFormVC = [[LoginFormViewController alloc] init];
    loginFormVC.title = _L(@"vc_title_006");
    
    //使用一个NavigationController来包裹登录视图
    UINavigationController* loginFormNC = [[UINavigationController alloc] initWithRootViewController:loginFormVC];
    [Helper navigationControllerCommonStyle:loginFormNC];
    
    //使用presentModal方式
    [self.navigationController presentModalViewController:loginFormNC animated:true];
}


@end
